package com.liu.resume.ui;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.liu.resume.R;

import common.pie.widget.DragCircle;
import common.pie.widget.PieChart;

/**
 * Created by Administrator on 2016/9/22.
 */
public class HomeFragment extends Fragment implements View.OnClickListener, DragCircle.OnSelectListener {
    private PieChart mBPieChart, mMPieChart, mFPieChart;
    private TextView mBText, mMText, mFText;
    private DragCircle mDragCircle;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);

        initTop(view);

        mBText.setText("综合");
        mMText.setText("Github");
        mFText.setText("文章");

        mDragCircle = (DragCircle) view.findViewById(R.id.quick_drag);
        mDragCircle.setOnSelectListener(this);
        DragCircle.CircleTag[] tags = new DragCircle.CircleTag[5];
        final int defaultColor = getResources().getColor(R.color.black_alpha_16);
        int[] colors = new int[]{R.color.cyan_500, R.color.red_500, R.color.green_500, R.color.grey_500,R.color.blue_500,};
        String[] titles = new String[]{"基本资料", "技能", "经验", "期望","项目"};
        for (int i = 0; i < 5; i++) {
            int color = defaultColor;
            String str = "";
            color = getResources().getColor(colors[i]);
            str = titles[i];
            tags[i] = new DragCircle.CircleTag(color, str);
        }
        mDragCircle.setTag(tags);
        return view;
    }

    @SuppressLint("CutPasteId")
    private void initTop(View view) {
        // Find
        View layTop = view.findViewById(R.id.include_lay_birthday);
        mBPieChart = (PieChart) layTop.findViewById(R.id.item_sta_pie_chart);
        mBText = (TextView) layTop.findViewById(R.id.item_sta_txt);

        layTop = view.findViewById(R.id.include_lay_memorial);
        mMPieChart = (PieChart) layTop.findViewById(R.id.item_sta_pie_chart);
        mMText = (TextView) layTop.findViewById(R.id.item_sta_txt);

        layTop = view.findViewById(R.id.include_lay_future);
        mFPieChart = (PieChart) layTop.findViewById(R.id.item_sta_pie_chart);
        mFText = (TextView) layTop.findViewById(R.id.item_sta_txt);

        // Image
        mBPieChart.setImageResource(R.mipmap.ic_main_categrey);
        mMPieChart.setImageResource(R.mipmap.ic_main_github);
        mFPieChart.setImageResource(R.mipmap.ic_main_article);

        //mBPieChart.setOnClickListener(this);
        //mMPieChart.setOnClickListener(this);
        //mFPieChart.setOnClickListener(this);
    }

    private CharSequence getTopText(long occupancy, final String suffix) {
        final String str = " " + String.valueOf(occupancy) + suffix;
        final int len = str.length();
        final int lenFx = len - suffix.length();
        final Resources resources = getResources();

        SpannableString span = new SpannableString(str);
        span.setSpan(new AbsoluteSizeSpan(resources.getDimensionPixelSize(R.dimen.font_20)),
                0, lenFx, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        span.setSpan(new ForegroundColorSpan(resources.getColor(R.color.white_alpha_224)),
                0, lenFx, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        return span;
    }


    @Override
    public void onClick(View v) {

    }

    @Override
    public void onSelect(int index) {
//        if (mNewestCaches == null)
//            return;
//        NewestModel cache = mNewestCaches[index];
//        if (cache != null) {
//            MainActivity activity = (MainActivity) getActivity();
//            RecordDetailActivity.actionStart(activity, cache.getId());
//            activity.setBlur(activity);
//        }
    }


}
